import Blockly from 'blockly/core'
import 'blockly/python_compressed'
import 'blockly/blockly_compressed'
import 'blockly/blocks_compressed'

// parseInt函数模块，将非int类型数据转换为int
Blockly.Blocks.math_floor = {
  init: function () {
    this.appendValueInput('parsing_state')
      .setCheck(['Number'])
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField('math.floor(')
    this.appendDummyInput().appendField(')')
    this.setInputsInline(true)
    this.setOutput(true, 'Number')
    this.setColour(210)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

// 代码格式：int(statement)
Blockly.Python.math_floor = function (block) {
  const valueParsingState = Blockly.Python.valueToCode(
    block,
    'parsing_state',
    Blockly.Python.ORDER_NONE
  )
  const code = 'math.floor(' + valueParsingState + ')'
  return [code, Blockly.Python.ORDER_NONE]
}

export default Blockly
